<template>
	<div class="orgBusinessEdit">
		<titleDiv :title="title" :isShow="true" text1="创建人：" text2="创建时间：" :value1="edit.name" :value2="edit.creatTime"></titleDiv>
		<div class="main">
			<el-form ref="form" :model="form" label-width="80px">
				<el-form-item label="业务名称">
					<el-input v-model="form.name" placeholder="如：个人工商局商户业务"></el-input>
				</el-form-item>
				<el-form-item label="业务描述">
					<el-input v-model="form.describe" class="textArea" type="textarea" placeholder="业务描述，子业务类型以及办理业务所需材料。"></el-input>
				</el-form-item>
				<el-button class="btn" type="primary" @click="editBusinessType">提交</el-button>
			</el-form>
		</div>
	</div>
</template>
<script>
	import titleDiv from './view/titleDiv.vue'
	import {orgDetailBusiness,orgEditBusiness} from '../api/getData.js'
	export default {
		name: 'orgBusinessEdit',
		data: function() {
			return {
				title: "编辑业务类型",
				businessId: '',
				edit: {},
				form: {
					name: '',
					describe: ''
				}
			}
		},
		components: {
			titleDiv
		},
		created() {
			this.getParams()
			this.getDetail()
		}, // 创建时
		beforeMount: function() {}, // 挂载之前
		mounted: function() {}, // 挂载之后
		beforeUpdate: function() {}, // 数据更新时调用,在渲染之前
		updated: function() {}, // 数据更新后,渲染后调用(禁止)
		beforeDestroy: function() {}, // 实例销毁前调用,解绑中间层的数据传输
		destroyed: function() {}, // 实例销毁后调用
		methods: {
			getParams() {
				console.log(this.$route.query.id, "传来的参数")
				this.businessId = this.$route.query.id
			},
			getDetail() {
				orgDetailBusiness({
					id: this.businessId
				}).then((res) => {
					console.log(res.data)
					this.edit = res.data.data
					this.form.name = res.data.data.businessName
					this.form.describe = res.data.data.businessDescription
				}).catch((error) => {
					console.log(error)
				})
			},
			// 修改业务类型
			editBusinessType() {
				orgEditBusiness({
					businessName: this.form.name,
					businessDescription: this.form.describe,
					id: this.businessId
				}).then((res) => {
					console.log(res.data, "修改业务类型")
					if (res.data.code == 0) {
						this.$message({
							message: res.data.msg,
							type: 'success'
						});
						setTimeout(() => {
							this.$router.push('/orgBusiness/orgBusinessIndex')
						}, 1000)
					}
				}).catch((error) => {
					console.log(error)
				})
			}
		} // 函数
	}
</script>
<style lang='scss'>
	.orgBusinessEdit {
		box-sizing: border-box;

		.main {
			background: #fff;
			width: 100%;
			margin-top: 3%;
			padding: 5% 20%;

			.textArea {
				textarea {
					min-height: 240px !important;
				}

			}

			.el-form-item__label {
				font-weight: bold;
			}

			.btn {
				width: 120px;
				height: 32px;
				line-height: 1px;
				margin-left: 80px;
			}
		}
	}
</style>
